<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<?php
/**
 * Wishlist view template
 *
 * @deprecated since 1.12.0.0
 */
$entityValues = $this->getEntityValues();
?>
<div class="my-wishlist">
    <div class="page-title title-buttons">
        <?php if ($this->helper('wishlist')->isRssAllow() && $this->hasWishlistItems()): ?>
            <a href="<?php echo $this->helper('wishlist')->getRssUrl(); ?>" class="link-rss"><?php echo $this->__('RSS Feed') ?></a>
        <?php endif; ?>
        <h1><?php echo $this->__('My Wishlist') ?></h1>
    </div>
    <?php echo $this->getMessagesBlock()->toHtml() ?>

    <?php if ($this->hasWishlistItems()): ?>
    <form id="wishlist-view-form" action="<?php echo $this->getUrl('*/*/update') ?>" method="post">
        <fieldset>
            <?php echo $this->getBlockHtml('formkey')?>
            <table class="data-table" id="wishlist-table">
            <col width="1" />
            <col />
            <?php if ($this->getEnabled()): ?>
            <col width="1" />
            <?php endif; ?>
            <col width="1" />
            <col width="1" />
            <col width="1" />
                <thead>
                    <tr>
                        <th><?php echo $this->__('Product') ?></th>
                        <th><?php echo $this->__('Comment') ?></th>
                        <th class="a-center"><span class="nobr"><?php echo $this->__('Added On') ?></span></th>
                        <?php if ($this->getEnabled() && $entityValues): ?>
                            <th class="a-center"><span class="nobr"><?php echo $this->__('Add to Gift Registry') ?></span></th>
                        <?php endif; ?>
                        <th class="a-center"><span class="nobr"><?php echo $this->__('Add to Cart') ?></span></th>
                        <th>&nbsp;</th>
                    </tr>
                </thead>
                <?php foreach ($this->getWishlistItems() as $item): ?>
                    <?php
                        $product = $item->getProduct();
                        $isVisibleProduct = $product->isVisibleInSiteVisibility();
                    ?>
                    <tbody>
                        <tr>
                            <td>
                                <a class="product-image" href="<?php echo $this->getProductUrl($item) ?>" title="<?php echo $this->escapeHtml($product->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(113, 113); ?>" width="113" height="113" alt="<?php echo $this->escapeHtml($product->getName()) ?>" /></a>
                                <h2 class="product-name"><a href="<?php echo $this->getProductUrl($item) ?>"><?php echo $this->escapeHtml($product->getName()) ?></a></h2>
                            </td>
                            <td>
                                <textarea name="description[<?php echo $item->getWishlistItemId() ?>]" rows="3" cols="5" onfocus="focusComment(this)" onblur="focusComment(this)" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Comment')) ?>"><?php echo $this->getCommentValue($item); ?></textarea>
                            </td>
                            <td>
                                <span class="nobr"><?php echo $this->getFormatedDate($item->getAddedAt()) ?></span>
                            </td>
                            <?php if ($this->getEnabled() && $entityValues):?>
                            <td>
                                <?php if ($this->checkProductType($product)): ?>
                                <div class="btn-gift-registry">
                                    <div class="input-box">
                                        <select id="giftregistry_entity_<?php echo $item->getId() ?>" name="entity" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Gift Registry')) ?>" >
                                            <?php foreach ($entityValues as $_entity):?>
                                                <option value="<?php echo $_entity->getValue()?>" title="<?php echo $this->escapeHtml($_entity->getTitle())?>"><?php echo $this->escapeHtml($this->helper('core/string')->truncate($_entity->getTitle(), 40))?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                    <button type="button" onclick="addProductToGiftregistry('<?php echo $item->getId() ?>')" class="button btn-cart"><span><span><?php echo $this->__('Add to Gift Registry') ?></span></span></button>
                                </div>
                                <?php endif;?>
                            </td>
                            <?php endif;?>
                            <td class="a-center">
                            <?php if ($item->canHaveQty() && $isVisibleProduct): ?>
                                <p><input type="text" class="input-text qty" name="qty[<?php echo $item->getId() ?>]" value="<?php echo $this->getAddToCartQty($item) * 1 ?>" /></p>
                            <?php endif; ?>
                            <?php if ($product->isSaleable()): ?>
                                <?php if ($isVisibleProduct): ?>
                                <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Cart')) ?>" onclick="addWItemToCart(<?php echo $item->getId(); ?>)" class="button btn-cart"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                                <?php endif ?>
                            <?php else: ?>
                                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                            <?php endif; ?>
                                <?php if ($isVisibleProduct): ?>
                                <p><a href="<?php echo $this->getItemConfigureUrl($item) ?>"><?php echo $this->__('Edit') ?></a></p>
                                <?php endif ?>
                            </td>
                            <td>
                                <a href="<?php echo $this->getItemRemoveUrl($item) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Remove Item')) ?>" onclick="return confirmRemoveWishlistItem();" class="btn-remove btn-remove2"><?php echo $this->__('Remove item')?></a>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="<?php echo ($this->getEnabled() && $entityValues)? "5" : "6"; ?>">
                                <?php echo $this->getPriceHtml($product, true) ?>
                                <?php echo $this->getDetailsHtml($item) ?>
                            </td>
                        </tr>
                    </tbody>
                <?php endforeach ?>
            </table>
            <script type="text/javascript">decorateTable('wishlist-table', {'tbody' : ['odd', 'even', 'first', 'last'], 'tbody tr' : ['first', 'last']})</script>
            <div class="buttons-set buttons-set2">
                <button type="submit" onclick="this.name='save_and_share'" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Share Wishlist')) ?>" class="button btn-share"><span><span><?php echo $this->__('Share Wishlist') ?></span></span></button>
                <?php if($this->isSaleable()):?>
                    <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add All to Cart')) ?>" onclick="addAllWItemsToCart()" class="button btn-add"><span><span><?php echo $this->__('Add All to Cart') ?></span></span></button>
                <?php endif;?>
                <button type="submit" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Update Wishlist')) ?>" onclick="this.name='do'" class="button btn-update"><span><span><?php echo $this->__('Update Wishlist') ?></span></span></button>
            </div>
        </fieldset>
    </form>
    <?php else: ?>
        <p><?php echo $this->__('You have no items in your wishlist.') ?></p>
    <?php endif ?>
    <form action="<?php echo $this->getAddUrl();?>" method="post" id="giftregistry-form">
        <div class="no-display">
            <input type="hidden" name="item" value="" />
            <input type="hidden" name="entity" value="" />
        </div>
    </form>

    <script type="text/javascript">
    //<![CDATA[
    function addProductToGiftregistry(itemId) {
        giftregistryForm = $('giftregistry-form');
        var entity = $('giftregistry_entity_' + itemId);
        entity.addClassName('required-entry');
        if (Validation.validate($('giftregistry_entity_' + itemId))) {
            giftregistryForm.entity.value = entity.value;
            giftregistryForm.item.value = itemId;
            giftregistryForm.submit();
        }
        entity.removeClassName('required-entry');
    }

    function confirmRemoveWishlistItem() {
        return confirm('<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Are you sure you want to remove this product from your wishlist?')) ?>');
    }

    function focusComment(obj) {
        if( obj.value == '<?php echo $this->helper('wishlist')->defaultCommentString() ?>' ) {
            obj.value = '';
        } else if( obj.value == '' ) {
            obj.value = '<?php echo $this->helper('wishlist')->defaultCommentString() ?>';
        }
    }

    function updateAction(addAction) {
        viewForm = $('wishlist-view-form');
        viewForm.action = addAction;
        viewForm.submit();
    }

    function addWItemToCart(itemId) {
        var url = '<?php echo $this->getItemAddToCartUrl('%item%') ?>';
        url = url.gsub('%item%', itemId);
        var form = $('wishlist-view-form');
        if (form) {
            var input = form['qty[' + itemId + ']'];
            if (input) {
                var separator = (url.indexOf('?') >= 0) ? '&' : '?';
                url += separator + input.name + '=' + encodeURIComponent(input.value);
            }
        }
        setLocation(url);
    }

    function addAllWItemsToCart() {
        var url = '<?php echo $this->getUrl('*/*/allcart') ?>';
        var separator = (url.indexOf('?') >= 0) ? '&' : '?';
        $$('#wishlist-view-form .qty').each(
            function (input, index) {
                url += separator + input.name + '=' + encodeURIComponent(input.value);
                separator = '&';
            }
        );
        setLocation(url);
    }
    //]]>
    </script>
</div>
<div class="buttons-set">
    <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
</div>
